package coupon_distribution

import (
	sqlc "bp/db/sqlc"
	couponDistributionGrpc "bp/rpc/gen/webapi/coupon_distribution"
)

type CouponDistributionPtrEntityToPbFunc func(*sqlc.CouponDistribution) *couponDistributionGrpc.CouponDistributionEntity
type CouponDistributionPtrArrayEntityToPbFunc func([]*sqlc.CouponDistribution) []*couponDistributionGrpc.CouponDistributionEntity

// ConvCouponDistributionPtrEntityToPb get func of *sqlc.CouponDistribution => *couponDistributionGrpc.CouponDistributionEntity
func (s *CouponDistributionWebApiImp) ConvCouponDistributionPtrEntityToPb() CouponDistributionPtrEntityToPbFunc {
	return func(ptr *sqlc.CouponDistribution) *couponDistributionGrpc.CouponDistributionEntity {
		if ptr == nil {
			return nil
		}
		return &couponDistributionGrpc.CouponDistributionEntity{
			Id:              ptr.ID,
			CouponId:        ptr.CouponID,
			Issuer:          ptr.Issuer,
			DistributeScene: ptr.DistributeScene,
			BatchNo:         ptr.BatchNo,
			Cnt:             ptr.Cnt,
			IsExecuting:     ptr.IsExecuting,
			IsExecuted:      ptr.IsExecuted,
			Executed:        sqlc.GoNTimeToPBTimestamp(ptr.Executed),
			IsAnyoneGot:     ptr.IsAnyoneGot,
			Memo:            ptr.Memo.String,
		}
	}
}

// ConvCouponDistributionArrayPtrEntityToPb get func of []*sqlc.CouponDistribution => []*couponDistributionGrpc.CouponDistributionEntity
func (s *CouponDistributionWebApiImp) ConvCouponDistributionPtrArrayEntityToPb() CouponDistributionPtrArrayEntityToPbFunc {
	return func(ptrs []*sqlc.CouponDistribution) (vPtrs []*couponDistributionGrpc.CouponDistributionEntity) {
		for _, ptr := range ptrs {
			vPtrs = append(vPtrs, s.ConvCouponDistributionPtrEntityToPb()(ptr))
		}
		return
	}
}

type CouponDistributionWithStatPtrEntityToPbFunc func(*sqlc.ListCouponDistributionWithStatsByCouponIDAndIssuesAndDistributeScenesRow) *couponDistributionGrpc.CouponDistributionWithStatEntity
type CouponDistributionWithStatPtrArrayEntityToPbFunc func([]*sqlc.ListCouponDistributionWithStatsByCouponIDAndIssuesAndDistributeScenesRow) []*couponDistributionGrpc.CouponDistributionWithStatEntity

// ConvCouponDistributionWithStatPtrEntityToPb get func of *sqlc.ListCouponDistributionWithStatsByCouponIDAndIssuesAndDistributeScenesRow => *couponDistributionGrpc.CouponDistributionWithStatEntity
func (s *CouponDistributionWebApiImp) ConvCouponDistributionWithStatPtrEntityToPb() CouponDistributionWithStatPtrEntityToPbFunc {
	return func(ptr *sqlc.ListCouponDistributionWithStatsByCouponIDAndIssuesAndDistributeScenesRow) *couponDistributionGrpc.CouponDistributionWithStatEntity {
		if ptr == nil {
			return nil
		}
		return &couponDistributionGrpc.CouponDistributionWithStatEntity{
			Self: &couponDistributionGrpc.CouponDistributionEntity{
				Id:              ptr.ID,
				CouponId:        ptr.CouponID,
				Issuer:          ptr.Issuer,
				DistributeScene: ptr.DistributeScene,
				BatchNo:         ptr.BatchNo,
				Cnt:             ptr.Cnt,
				IsExecuting:     ptr.IsExecuting,
				IsExecuted:      ptr.IsExecuted,
				Executed:        sqlc.GoNTimeToPBTimestamp(ptr.Executed),
				IsAnyoneGot:     ptr.IsAnyoneGot,
				Memo:            ptr.Memo.String,
			},
			Stat: &couponDistributionGrpc.CouponDistributionStatEntity{
				DistributedCnt:    ptr.DistributedCnt,
				GotCnt:            ptr.GotCnt,
				UseCnt:            ptr.UseCnt,
				UseAmount:         ptr.UseAmount,
				OffTransCnt:       ptr.OffTransCnt,
				OffAmount:         ptr.OffAmount,
				OffRefundTransCnt: ptr.OffRefundTransCnt,
				OffRefundAmount:   ptr.OffRefundAmount,
			},
		}
	}
}

// ConvCouponDistributionWithStatPtrArrayEntityToPb get func of []*sqlc.ListCouponDistributionWithStatsByCouponIDAndIssuesAndDistributeScenesRow => []*couponDistributionGrpc.CouponDistributionWithStatEntity
func (s *CouponDistributionWebApiImp) ConvCouponDistributionWithStatPtrArrayEntityToPb() CouponDistributionWithStatPtrArrayEntityToPbFunc {
	return func(ptrs []*sqlc.ListCouponDistributionWithStatsByCouponIDAndIssuesAndDistributeScenesRow) (vPtrs []*couponDistributionGrpc.CouponDistributionWithStatEntity) {
		for _, ptr := range ptrs {
			vPtrs = append(vPtrs, s.ConvCouponDistributionWithStatPtrEntityToPb()(ptr))
		}
		return
	}
}
